home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / tcpip / amiga / asrc29p.lha / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  13.1 KB  |  576 lines

  1. /* Stuff heavily dependent on the configuration info in config.h */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "proc.h"
  8. #include "cmdparse.h"
  9. #include "config.h"
  10. #include "daemon.h"
  11. #include "timer.h"
  12. #include "iface.h"
  13. #include "ppp.h"
  14. #include "slip.h"
  15. #include "usock.h"
  16. #include "socket.h"
  17. #include "kiss.h"
  18. #include "enet.h"
  19. #include "ax25.h"
  20. #include "netrom.h"
  21. #include "ip.h"
  22. #include "tcp.h"
  23. #include "udp.h"
  24. #include "commands.h"
  25. #include "rspf.h"
  26.  
  27. static int dostart __ARGS((int argc,char *argv[],void *p));
  28. static int dostop __ARGS((int argc,char *argv[],void *p));
  29. static int domessage __ARGS((int argc,char *argv[],void *p));
  30.  
  31. struct mbuf *Hopper;
  32. unsigned Nsessions = NSESSIONS;
  33. int32 Heapsize = HEAPSIZE * (long)1024;
  34.  
  35. /* Free memory threshold, below which things start to happen to conserve
  36.  * memory, like issuing source quenches and refusing connects
  37.  */
  38. int32 Memthresh = MTHRESH;
  39.  
  40. /* daemons to be run at startup time */
  41. struct daemon Daemons[] = {
  42.     "killer",    200,    killer,
  43.     "timer",    1024,    timerproc,
  44.     "network",    1536,    network,
  45.     "keyboard",    250,    keyboard,
  46.     NULLCHAR,    0,    NULLVFP
  47. };
  48.  
  49. struct iftype Iftypes[] = {
  50.     /* This entry must be first, since Loopback refers to it */
  51.     "None",        NULL,        NULL,        NULL,
  52.     NULL,        TYPE_NONE,    0,
  53.  
  54. #ifdef    AX25
  55.     "AX25",        ax_send,    ax_output,    pax25,
  56.     setcall,    TYPE_AX25,    AXALEN,
  57. #endif
  58.  
  59. #ifdef    SLIP
  60.     "SLIP",        slip_send,    NULL,        NULL,
  61.     NULL,        TYPE_IP,    0,
  62. #endif
  63.  
  64. #ifdef    ETHER
  65.     /* Note: NULL is specified for the scan function even though
  66.      * gether() exists because the packet drivers don't support
  67.      * address setting.
  68.      */
  69.     "Ethernet",    enet_send,    enet_output,    pether,
  70.     NULL,        TYPE_ETHER,    EADDR_LEN,
  71. #endif
  72.  
  73. #ifdef    NETROM
  74.     "NETROM",    nr_send,    NULL,        pax25,
  75.     setcall,    TYPE_NETROM,    AXALEN,
  76. #endif
  77. #ifdef PPP
  78.     "PPP",        ppp_send,    ppp_output,    NULL,
  79.     NULL,        TYPE_PPP,        0,
  80. #endif    /* PPP */
  81.  
  82.     NULLCHAR
  83. };
  84.  
  85. /* Command lookup and branch tables */
  86. struct cmds Cmds[] = {
  87.     /* The "go" command must be first */
  88.     "",        go,        0, 0, NULLCHAR,
  89.     "!",            doshell,        0, 0, NULLCHAR,
  90.     "abort",    doabort,    0, 0, NULLCHAR,
  91.     "amiga",    doamiga,    0, 0, NULLCHAR,
  92. #if    (defined(AX25) || defined(ETHER) || defined(APPLETALK))
  93.     "arp",        doarp,        0, 0, NULLCHAR,
  94. #endif
  95. #ifdef    ASY
  96.     "asystat",    doasystat,    0, 0, NULLCHAR,
  97. #endif
  98.     "attach",    doattach,    0, 2,
  99.         "attach <hardware> <hw specific options>",
  100. #ifdef    AX25
  101.     "ax25",        doax25,        0, 0, NULLCHAR,
  102. #endif    
  103. #ifdef    MAILBOX
  104.     "bbs",        dobbschat,    1024, 0, NULLCHAR,
  105. #endif
  106. /* This one is out of alpabetical order to allow abbreviation to "c" */
  107. #ifdef    AX25
  108.     "connect",    doconnect,    1024, 3,"connect <interface> <callsign>",
  109. #endif
  110.     "cd",        docd,        0, 0, NULLCHAR,
  111. #ifdef    CHATNODE
  112.     "chatnode",    dobbschat,    1024, 0, NULLCHAR,
  113. #endif
  114.     "close",    doclose,    0, 0, NULLCHAR,
  115.     "disconnect",    doclose,    0, 0, NULLCHAR,
  116. #ifdef    DIGGER
  117.     "digger",    dodigger,    0, 0, NULLCHAR,
  118. #endif
  119.     "dir",        dodir,        0, 0, NULLCHAR,
  120.     "detach",    dodetach,    0, 2, "detach <interface>",
  121.     "domain",    dodomain,    0, 0, NULLCHAR,
  122.     "echo",        doecho,        0, 0, NULLCHAR,
  123.     "eol",        doeol,        0, 0, NULLCHAR,
  124.     "escape",    doescape,    0, 0, NULLCHAR,
  125.     "exit",        doexit,        0, 0, NULLCHAR,
  126.     "finger",    dofinger,    1024, 2, "finger name@host",
  127.     "ftp",        doftp,        2048, 2, "ftp <address>",
  128.     "ftpdown",    doftpdown,    0, 0, NULLCHAR,
  129.     "help",        dohelp,        0, 0, NULLCHAR,
  130.     "hopcheck",    dohop,        0, 0, NULLCHAR,
  131.     "hostname",    dohostname,    0, 0, NULLCHAR,
  132.     "icmp",        doicmp,        0, 0, NULLCHAR,
  133.     "ifconfig",    doifconfig,    0, 0, NULLCHAR,
  134.     "ip",        doip,        0, 0, NULLCHAR,
  135.     "kick",        dokick,        0, 0, NULLCHAR,
  136.     "less",        doless,        512, 2, "less <filename>",
  137. #ifdef    MAILBOX
  138.     "mbox",        dombox,        0, 0, NULLCHAR,
  139. #endif
  140.     "mem",        domem,        0, 0, NULLCHAR,
  141.     "message",    domessage,    0, 2, "message <socket> <msg>",
  142. #ifdef    AX25
  143.     "mode",        domode,        0, 2, "mode <interface>",
  144. #endif
  145. #ifdef    NETROM
  146.     "netrom",    donetrom,    0, 0, NULLCHAR,
  147. #ifdef    NRS
  148.     "nrstat",    donrstat,    0, 0, NULLCHAR,
  149. #endif    /* NRS */
  150. #endif    /* NETROM */
  151. #ifdef    NNTP
  152.     "nntp",        donntp,        0, 0, NULLCHAR,
  153. #endif
  154.     "param",    doparam,    0, 2, "param <interface>",
  155.     "ping",        doping,        512, 2, "ping <host> [<length> [<interval> [incflag]]]",
  156. #ifdef    POP2
  157.     "pop2",        dopop2,        0, 0, NULLCHAR,
  158. #endif
  159. #ifdef    POP3
  160.     "pop3",        dopop3,        0, 0, NULLCHAR,
  161. #endif
  162. #ifdef PPP
  163.     "ppp",        dopppcontrol,    0, 0, NULLCHAR,
  164. #endif    /* PPP */
  165.     "ps",        ps,        0, 0, NULLCHAR,
  166.     "pwd",        docd,        0, 0, NULLCHAR,
  167.     "record",    dorecord,    0, 0, NULLCHAR,
  168.     "remote",    doremote,    0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick",
  169.     "reset",    doreset,    0, 0, NULLCHAR,
  170. #ifdef    RLOGINCLI
  171.     "rlogin",    dorlogin,    2048, 2, "rlogin <address>",
  172. #endif
  173. #ifdef    RIP
  174.     "rip",        dorip,        0, 0, NULLCHAR,
  175. #endif
  176.     "route",    doroute,    0, 0, NULLCHAR,
  177. #ifdef    RSPF
  178.     "rspf",        dorspf,        0, 0, NULLCHAR,
  179. #endif    /* RSPF */
  180.     "session",    dosession,    0, 0, NULLCHAR,
  181.     "shell",    doshell,    0, 0, NULLCHAR,
  182.     "smtp",        dosmtp,        0, 0, NULLCHAR,
  183.     "socket",    dosock,        0, 0, NULLCHAR,
  184.     "source",    dosource,    0, 2, "source <filename>",
  185. #ifdef    SERVERS
  186.     "start",    dostart,    0, 2, "start <servername>",
  187.     "stop",        dostop,        0, 2, "stop <servername>",
  188. #endif
  189.     "status",    dostatus,    0, 0, NULLCHAR,
  190.     "tcp",        dotcp,        0, 0, NULLCHAR,
  191.     "telnet",    dotelnet,    1024, 2, "telnet <address>",
  192. #ifdef STIMEOUT
  193.     "timeout",    dotimeout,    0, 0, NULLCHAR,
  194. #endif
  195. #ifdef    TRACE
  196.     "trace",    dotrace,    0, 0, NULLCHAR,
  197. #endif
  198.     "ttylink",    dotelnet,    1024, 2, "ttylink <address>",
  199.     "udp",        doudp,        0, 0, NULLCHAR,
  200.     "upload",    doupload,    0, 0, NULLCHAR,
  201.     "?",        dohelp,        0, 0, NULLCHAR,
  202.     NULLCHAR,    NULLFP,        0, 0,
  203.         "Unknown command; type \"?\" for list",
  204. };
  205.  
  206. /* List of supported hardware devices */
  207. struct cmds Attab[] = {
  208. #ifdef    PC_EC
  209.     /* 3-Com Ethernet interface */
  210.     "3c500", ec_attach, 0, 7, 
  211.     "attach 3c500 <address> <vector> arpa <label> <buffers> <mtu> [ip_addr]",
  212. #endif
  213. #ifdef    ASY
  214.     /* Ordinary PC asynchronous adaptor */
  215.     "asy", asy_attach, 0, 8, 
  216. #ifndef    AMIGA
  217.     "attach asy <address> <vector> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
  218. #else
  219.      "attach asy <driver> <unit> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
  220. #endif    /* AMIGA */
  221. #endif    /* ASY */
  222. #ifdef    KISS
  223.     /* Multi-port KISS interface piggy-backing on ASY interface. */
  224.     "kiss", kiss_attach, 0, 4, 
  225.     "attach kiss <asy_interface_label> <port> <label> [mtu]",
  226. #endif    /* KISS */
  227. #ifdef    PC100
  228.     /* PACCOMM PC-100 8530 HDLC adaptor */
  229.     "pc100", pc_attach, 0, 8, 
  230.     "attach pc100 <address> <vector> ax25 <label> <buffers>\
  231.  <mtu> <speed> [ip_addra] [ip_addrb]",
  232. #endif
  233. #ifdef    DRSI
  234.     /* DRSI PCPA card in low speed mode */
  235.     "drsi", dr_attach, 0, 8,
  236.     "attach drsi <address> <vector> ax25 <label> <bufsize> <mtu>\
  237. <chan a speed> <chan b speed> [ip addr a] [ip addr b]",
  238. #endif
  239. #ifdef    EAGLE
  240.     /* EAGLE RS-232C 8530 HDLC adaptor */
  241.     "eagle", eg_attach, 0, 8,
  242.     "attach eagle <address> <vector> ax25 <label> <buffers>\
  243.  <mtu> <speed> [ip_addra] [ip_addrb]",
  244. #endif
  245. #ifdef    HAPN
  246.     /* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
  247.     "hapn", hapn_attach, 0, 8,
  248.     "attach hapn <address> <vector> ax25 <label> <rx bufsize>\
  249.  <mtu> csma|full [ip_addr]",
  250. #endif
  251. #ifdef    APPLETALK
  252.     /* Macintosh AppleTalk */
  253.     "0", at_attach, 0, 7,
  254.     "attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu> [ip_addr]",
  255. #endif
  256. #ifdef NETROM
  257.     /* fake netrom interface */
  258.     "netrom", nr_attach, 0, 1,
  259.     "attach netrom [ip_addr]",
  260. #endif
  261. #ifdef    PACKET
  262.     /* FTP Software's packet driver spec */
  263.     "packet", pk_attach, 0, 4,
  264.     "attach packet <int#> <label> <buffers> <mtu> [ip_addr]",
  265. #endif
  266. #ifdef    HS
  267.     /* Special high speed driver for DRSI PCPA or Eagle cards */
  268.     "hs", hs_attach, 0, 7,
  269.     "attach hs <address> <vector> ax25 <label> <buffers> <mtu>\
  270.  <txdelay> <persistence> [ip_addra] [ip_addrb]",
  271. #endif
  272. #ifdef SCC
  273.     "scc", scc_attach, 0, 7,
  274.      "\nattach scc <devices> init <addr> <spacing> <Aoff> <Boff> <Dataoff>\
  275. \n   <intack> <vec> [p]<clock> [hdwe] [param]\
  276. \nattach scc <chan> slip|kiss|nrs|ax25 <label> <mtu> <speed> <bufsiz> [call] ",
  277.   #endif
  278.     NULLCHAR,
  279. };
  280.  
  281. /* Packet tracing stuff */
  282. #include "trace.h"
  283. #ifdef    TRACE
  284.  
  285. /* Protocol tracing function pointers. Matches list of TYPE definitions
  286.  * in iface.h.
  287.  */
  288. struct trace Tracef[] = {
  289. #ifdef    AX25
  290.     ax_forus,    ax25_dump,    /* TYPE_AX25 */
  291. #else
  292.     NULLFP,        NULLVFP,
  293. #endif    /* AX25 */
  294.  
  295. #ifdef    ETHER                /* TYPE_ETHER */
  296.     ether_forus,    ether_dump,
  297. #else
  298.     NULLFP,        NULLVFP,
  299. #endif    /* ETHER */
  300.  
  301.     NULLFP,        ip_dump,    /* TYPE_IP */
  302.  
  303. #ifdef    APPLETALK
  304.     at_forus,    at_dump,    /* TYPE_APPLETALK */
  305. #else
  306.     NULLFP,        NULLVFP,
  307. #endif    /* APPLETALK */
  308.  
  309. #ifdef    KISS                /* TYPE_KISS */
  310.     ki_forus,    ki_dump,
  311. #else
  312.     NULLFP,        NULLVFP,
  313. #endif    /* KISS */
  314.  
  315. #ifdef    NETROM                /* TYPE_NETROM */
  316.     NULLFP,        ip_dump,
  317. #else
  318.     NULLFP,        NULLVFP,
  319. #endif    
  320.  
  321.     NULLFP,        ip_dump,    /* TYPE_NONE */
  322.     NULLFP,        ip_dump,    /* TYPE_SLIP */
  323.  
  324. #ifdef PPP
  325.     NULLFP,        ppp_dump,    /* TYPE_PPP */
  326. #else
  327.     NULLFP,        NULLVFP,
  328. #endif /* PPP */
  329. };
  330.  
  331. #else    /* TRACE */
  332.  
  333. /* Stubs for tracing disabled */
  334. struct trace Tracef[] = {
  335.     NULLFP        /* No tracing at all */
  336. };
  337.  
  338. void
  339. dump(iface,direction,type,bp)
  340. struct iface *iface;
  341. int direction;
  342. unsigned type;
  343. struct mbuf *bp;
  344. {
  345. }
  346. #endif    /* TRACE */
  347.  
  348.  
  349. #if    defined(AX25) && !defined(NETROM)
  350. /* Stubs for when ax25 is configured wihtout net/rom */
  351. void
  352. nr_route(bp,iaxp)
  353. struct mbuf *bp;
  354. struct ax25_cb *iaxp;
  355. {
  356.     free_p(bp);
  357. }
  358. void
  359. nr_nodercv(iface,source,bp)
  360. struct iface *iface;
  361. char *source;
  362. struct mbuf *bp;
  363. {
  364.     free_p(bp);
  365. }
  366. #endif    /* defined(AX25) && !defined(NETROM) */
  367.  
  368.  
  369. #ifndef    RIP
  370. /* Stub for routing timeout when RIP is not configured -- just remove entry */
  371. void
  372. rt_timeout(s)
  373. void *s;
  374. {
  375.     struct route *stale = (struct route *)s;
  376.  
  377.     rt_drop(stale->target,stale->bits);
  378. }
  379. #endif
  380.  
  381. #ifdef    SERVERS
  382. /* "start" and "stop" subcommands */
  383. static struct cmds Startcmds[] = {
  384. #if    defined(AX25) && defined(MAILBOX)
  385.     "ax25",        ax25start,    256, 0, NULLCHAR,
  386. #endif
  387. #ifdef    CHATNODE
  388.     "chatnode",    conv1,    384, 0, NULLCHAR,
  389. #endif
  390.     "discard",    dis1,        256, 0, NULLCHAR,
  391.     "echo",        echo1,        256, 0, NULLCHAR,
  392.     "finger",    finstart,    256, 0, NULLCHAR,
  393.     "ftp",        ftpstart,    256, 0, NULLCHAR,
  394. #if    defined(NETROM) && defined(MAILBOX)
  395.     "netrom",    nr4start,    256, 0, NULLCHAR,
  396. #endif
  397. #ifdef    POP2
  398.     "pop2",        pop2start,    256, 0, NULLCHAR,
  399. #endif
  400. #ifdef    POP3
  401.     "pop3",        pop3start,    256, 0, NULLCHAR,
  402. #endif
  403. #ifdef    RIP
  404.     "rip",        doripinit,    0,   0, NULLCHAR,
  405. #endif
  406.     "smtp",        smtp1,        256, 0, NULLCHAR,
  407. #if    defined(MAILBOX)
  408.     "telnet",    telnet1,    256, 0, NULLCHAR,
  409. #endif
  410.     "ttylink",    ttylstart,    256, 0, NULLCHAR,
  411.     "remote",    rem1,        256, 0, NULLCHAR,
  412.     NULLCHAR,
  413. };
  414. static struct cmds Stopcmds[] = {
  415. #if    defined(AX25) && defined(MAILBOX)
  416.     "ax25",        ax250,        0, 0, NULLCHAR,
  417. #endif
  418. #ifdef    CHATNODE
  419.     "chatnode",    conv0,        0, 0, NULLCHAR,
  420. #endif
  421.     "discard",    dis0,        0, 0, NULLCHAR,
  422.     "echo",        echo0,        0, 0, NULLCHAR,
  423.     "finger",    fin0,        0, 0, NULLCHAR,
  424.     "ftp",        ftp0,        0, 0, NULLCHAR,
  425. #if    defined(NETROM) && defined(MAILBOX)
  426.     "netrom",    nr40,        0, 0, NULLCHAR,
  427. #endif
  428. #ifdef    POP2
  429.     "pop2",        pop2stop,    0, 0, NULLCHAR,
  430. #endif
  431. #ifdef    POP3
  432.     "pop3",        pop3stop,    0, 0, NULLCHAR,
  433. #endif
  434. #ifdef    RIP
  435.     "rip",        doripstop,    0, 0, NULLCHAR,
  436. #endif
  437.     "smtp",        smtp0,        0, 0, NULLCHAR,
  438. #ifdef    MAILBOX
  439.     "telnet",    telnet0,    0, 0, NULLCHAR,
  440. #endif
  441.     "ttylink",    ttyl0,        0, 0, NULLCHAR,
  442.     "remote",    rem0,        0, 0, NULLCHAR,
  443.     NULLCHAR,
  444.  
  445. };
  446.  
  447. static int
  448. dostart(argc,argv,p)
  449. int argc;
  450. char *argv[];
  451. void *p;
  452. {
  453.     return subcmd(Startcmds,argc,argv,p);
  454. }
  455.  
  456. static int
  457. dostop(argc,argv,p)
  458. int argc;
  459. char *argv[];
  460. void *p;
  461. {
  462.     return subcmd(Stopcmds,argc,argv,p);
  463. }
  464. #endif    /* SERVERS */
  465.  
  466. /* Various configuration-dependent functions */
  467.  
  468. /* Process packets in the Hopper */
  469. static void
  470. network(i,v1,v2)
  471. int i;
  472. void *v1;
  473. void *v2;
  474. {
  475.     struct mbuf *bp;
  476.     struct phdr phdr;
  477.     char i_state;
  478.  
  479. loop:    i_state = dirps();
  480.     while(Hopper == NULLBUF)
  481.         pwait(&Hopper);
  482.     restore(i_state);
  483.  
  484.     /* Process the input packet */
  485.     bp = dequeue(&Hopper);
  486.     pullup(&bp,(char *)&phdr,sizeof(phdr));
  487.     if(phdr.iface != NULLIF)
  488.         phdr.iface->rawrecvcnt++;
  489.     dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
  490.     switch(phdr.type){
  491. #ifdef    KISS
  492.     case TYPE_KISS:
  493.         kiss_recv(phdr.iface,bp);
  494.         break;
  495. #endif
  496. #ifdef    AX25
  497.     case TYPE_AX25:
  498.         ax_recv(phdr.iface,bp);
  499.         break;
  500. #endif
  501. #ifdef    ETHER
  502.     case TYPE_ETHER:
  503.         eproc(phdr.iface,bp);
  504.         break;
  505. #endif
  506. #ifdef PPP
  507.     case TYPE_PPP:
  508.         pproc(phdr.iface,bp);
  509.         break;
  510. #endif    /* PPP */
  511.     /* These types have no link layer protocol at the point when they're
  512.      * put in the hopper, so they can be handed directly to IP. The
  513.      * separate types are just for user convenience when running the
  514.      * "iface" command.
  515.      */
  516.     case TYPE_NETROM:
  517.     case TYPE_SLIP:
  518.     case TYPE_IP:
  519.     case TYPE_NONE:
  520.         ip_route(phdr.iface,bp,0);
  521.         break;
  522.     case TYPE_APPLETALK:
  523.     default:
  524.         free_p(bp);
  525.         break;
  526.     }
  527.     /* Let everything else run - this keeps the system from wedging
  528.      * when we're hit by a big burst of packets
  529.      */
  530.     pwait(NULL);
  531.     goto loop;
  532. }
  533.  
  534. static int
  535. domessage(argc,argv,p)
  536. int argc;
  537. char *argv[];
  538. void *p;
  539. {
  540.     char msg[256];
  541.     int sock[DEFNSOCK];
  542.     int count, i;
  543.  
  544.     /* command takes the form:
  545.  
  546.         message <one or more socket numbers> <message>
  547.  
  548.     the procedure constructs a list of socket numbers from the input
  549.     arguments, and constructs the message from the first argument that
  550.     is not a valid socket number */
  551.  
  552.     count = (argc < DEFNSOCK - 1) ? argc : DEFNSOCK -1;
  553.  
  554.     /* get socket args */
  555.     for (i=1; i<count ; i++)
  556.         if((sock[i] = atoi(argv[i])) == 0)
  557.             break;
  558.  
  559.     count = i;
  560.     msg[0] = '\0';
  561.  
  562.     /* collect rest of args as message */
  563.     for (;i<argc;i++) {
  564.         strcat(msg,argv[i]);
  565.         strcat(msg," ");
  566.     }
  567.  
  568.     /* output to all sockets */
  569.     for (i=1; i<count; i++)    {
  570.         usprintf(sock[i],"\a\n*** Message from %s:\n%s\n",Hostname,msg);
  571.         usflush(sock[i]);
  572.     }
  573.     return 0;
  574. }
  575.  
  576.